﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using JESAI.Application.Abstractions.Admin;
using JESAI.Application.Abstractions.Admin.Dtos.Project;
using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Service.Admin;
using JESAI.Core;
using JESAI.Framework.Filters;
using System;
using System.Threading.Tasks;

namespace Bucket.Admin.Web.Controllers
{
    /// <summary>
    /// 项目管理
    /// </summary>
    [ApiController]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class ProjectController : ControllerBase
    {
        private readonly IProjectService _projectService;
        private readonly IUser _user;
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="sqlSugarDbContextFactory"></param>
        /// <param name="mapper"></param>
        /// <param name="networkCommand"></param>
        /// <param name="user"></param>
        public ProjectController(IProjectService projectService, IUser user)
        {
            _projectService = projectService;
            _user = user;
        }

        /// <summary>
        /// 查看项目列表信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("/Project/QueryProject")]
        public BaseOutput<object> QueryProject()
        {
            var list = _projectService.QueryProject();
            return new BaseOutput<object> { Data = list };
        }

        /// <summary>
        /// 设置项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/Project/SetProject")]
        public BaseOutput SetProject([FromBody] SetProjectInput input)
        {
            long userId = _user.Id.ToLong();
            _projectService.UpdateOrInsert(input, userId);
            return new BaseOutput { };
        }

        /// <summary>
        /// 删除项目信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("/Project/DeleteProject")]
        public BaseOutput DeleteProject(long id)
        {
            _projectService.DeleteProject(id);
            return new BaseOutput { };
        }

        [HttpGet("/Project/DeleteProjects")]
        public BaseOutput DeleteProjects(long[] ids)
        {
            _projectService.DeleteProjects(ids);
            return new BaseOutput { };
        }

        /// <summary>
        /// 推送项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        //[HttpPost("/Project/PublishCommand")]
        //public async Task<BaseOutput> PublishCommand([FromBody] PublishCommandInput input)
        //{
        //    await _networkCommand.PublishCommandMessage(input.ProjectName, new Bucket.Values.NetworkCommand { CommandText = input.CommandText, NotifyComponent = input.CommandType });
        //    return new BaseOutput { };
        //}
    }

}